package com.koron.order.repair.controller;

import com.alibaba.fastjson.JSON;
import com.koron.bean.base.Response;
import com.koron.bean.workflow.RedirectQuery;
import com.koron.bean.workflow.WorkflowController;
import com.koron.common.core.config.ThreadLocalContext;
import com.koron.order.repair.service.RepairService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author jzp
 * @since 2022/9/14
 */
@Slf4j
@Api(tags = "计划检修工单")
@RestController
@RequestMapping("/ycRepair/waitReview")
public class RepairYcController implements WorkflowController {

    @Autowired
    private RepairService repairService;

    @Override
    public Response<Object> updateState(RedirectQuery redirectQuery) {
        log.info("业务单: {}, 工作流节点提交", JSON.toJSONString(redirectQuery));
        if (redirectQuery.getOperation() == 1 || redirectQuery.getOperation() == 256) {
            ADOConnection.runTask(ThreadLocalContext.get().getCurrDs(), repairService, "updateStatus", Boolean.class, redirectQuery.getDataId(), "DRAFT");
        } else {
            ADOConnection.runTask(ThreadLocalContext.get().getCurrDs(), repairService, "updateStatus", Boolean.class, redirectQuery.getDataId(), "WAIT_REVIEW");
        }
        return Response.success();
    }

    @Override
    public Response updateEnd(RedirectQuery redirectQuery) {
        log.info("业务单id: {}, 工作流节点提交", redirectQuery.getDataId());
        ADOConnection.runTask(ThreadLocalContext.get().getCurrDs(), repairService, "updateStatus", Boolean.class, redirectQuery.getDataId(), "WAIT_DISPATCH");
        return Response.success();
    }

    @Override
    public Response updateCancel(RedirectQuery redirectQuery) {
        log.info("业务单id: {}, 工作流作废", redirectQuery.getDataId());
        return Response.success();
    }
}
